#!/usr/bin/python
# -*- coding: gbk -*-
import sys
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import pyodbc
#engine = create_engine('postgresql://scott:tiger@localhost/')
#engine = create_engine('mssql+pyodbc://user:password@host:port/dbname')
engine = sqlalchemy.create_engine('mssql://qq399:123456@/?dsn=DSN55?charset=utf8')
Session = sessionmaker(bind=engine)
conn = engine.connect()
session = Session(bind=conn)

from sqlalchemy.dialects.mssql import \
    BIGINT, BINARY, BIT, CHAR, DATE, DATETIME, DATETIME2, \
    DATETIMEOFFSET, DECIMAL, FLOAT, IMAGE, INTEGER, MONEY, \
    NCHAR, NTEXT, NUMERIC, NVARCHAR, REAL, SMALLDATETIME, \
    SMALLINT, SMALLMONEY, SQL_VARIANT, TEXT, TIME, \
    TIMESTAMP, TINYINT, UNIQUEIDENTIFIER, VARBINARY, VARCHAR

from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()


class OrdersInfo(Base):
    __tablename__ = 'OrdersInfo'
    oinfoid = Column(INTEGER, primary_key=True)
    username = Column(VARCHAR)
    email = Column(VARCHAR)
    proid = Column(INTEGER)
    cityid = Column(INTEGER)
    gameusername = Column(VARCHAR)
    areaid = Column(INTEGER)
    orderno = Column(INTEGER)
    addtime = Column(DATETIME)
    areaName = Column(NVARCHAR)
    def __init__(self, oinfoid, username, email, proid, cityid, gameusername, areaid, orderno, addtime, areaName):
        self.oinfoid = oinfoid
	self.username = username
        self.email = email
        self.proid = proid
        self.cityid = cityid
        self.gameusername = gameusername
        self.areaid = areaid
        self.orderno = orderno
        self.addtime = addtime
	self.areaName = areaName
    def __repr__(self):
        return "<OrdersInfo('%d', '%s', '%s', '%d', '%d', '%s', '%d', '%s', '%s', '%r')>" % (self.oinfoid, self.username, self.email, self.proid, self.cityid, self.gameusername, self.areaid, self.orderno, self.addtime, self.areaName)


print (session.query(OrdersInfo).filter(OrdersInfo.username.like("%gc%")).all())


